<template>
  <div class="roleHistory">
    <div class="role-tab">
      <at-tabs class="right" v-model="tabTypeShow" @tab-click="changeTypeShow" type="border-card">
        <at-tab-pane name="add">
          <span slot="label">新增</span>
        </at-tab-pane>
        <at-tab-pane name="update">
          <span slot="label">修改</span>
        </at-tab-pane>
        <at-tab-pane name="delete">
          <span slot="label">删除</span>
        </at-tab-pane>
      </at-tabs>
    </div>
    <div class="role-table">
      <div class="table-title">
        角色变更历史列表
      </div>
      <div class="table-wrap">
        <div class="search">
          <at-search v-model="value" placeholder="角色名" type="text" project='mh' @keyup.enter.native="searchEvent" icon="search" :on-icon-click="searchEvent"/>
        </div>
        <div class="content">
          <at-table :data="history.tableData.dataSource" width="100%" :border="false" @sort-change='sortChange'>
          <at-table-column width="250px" align="left" prop="ar_time" sortable label="变更时间"></at-table-column>
          <at-table-column width="250px" align="left" prop="brole_id" label="角色Id"></at-table-column>
          <at-table-column width="250px" align="left" prop="brole_name" label="角色名称"></at-table-column>
          <at-table-column align="left" prop="dcn_name" label="功能权限" :show-overflow-tooltip="true"></at-table-column>
        </at-table>
        </div>
        <div class="page">
          <Pagination :currentPage="history.tableData.current" :total="history.tableData.total" :pageSizes="[20, 40, 60, 80]" :pageSize="history.tableData.pageSize" layout="slot, total, sizes, prev, pager, next, jumper" @size-change="handleSizeChange" @current-change="handleCurrentChange">
          </Pagination>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { mapActions, mapMutations, mapGetters } from 'vuex'
export default {
  data () {
    return {
      // 搜索字段
      value: '',
      tabTypeShow: 'add',
      baseSearch: {
        pagination: {
          current: 1, // 当前页码
          pageSize: 20 // 当前页显示的数据条数
        },
        search: {
          value: '' // 需要模糊搜索的值（搜索框）
        },
        sorter: {
          field: 'ar_time', // 排序的字段
          order: 'descend' // or "desc"升序还是降序
        }
      }
    }
  },
  methods: {
    ...mapActions('role', [
      'GET_HISTORY'
    ]),
    ...mapMutations('role', [
      'SET_HIST_PAGESIZE',
      'SET_HIST_CURRENT',
      'SET_TAB_TYPE'
    ]),
    // tab页切换
    changeTypeShow (el) {
      this.SET_TAB_TYPE(el.name)
      this.value = ''
      this.baseSearch.search.value = ''
      this.baseSearch.pagination.current = 1
      this.SET_HIST_CURRENT(1)
      // this.baseSearch.sorter.order = 'descend'
      this.GET_HISTORY(JSON.stringify(this.baseSearch))
    },
    // 每页条目改变
    handleSizeChange (value) {
      this.SET_HIST_CURRENT(1)
      this.SET_HIST_PAGESIZE(value)
      this.baseSearch.pagination.pageSize = value
      this.baseSearch.pagination.current = 1
      this.GET_HISTORY(JSON.stringify(this.baseSearch))
    },
    // 页码改变
    handleCurrentChange (value) {
      this.baseSearch.pagination.current = value
      this.SET_HIST_CURRENT(value)
      this.GET_HISTORY(JSON.stringify(this.baseSearch))
    },
    // 排序
    sortChange ({ prop, order }) {
      // order : descending, ascending
      if (order === null) {
      } else {
        this.SET_HIST_CURRENT(1)
        this.baseSearch.pagination.current = 1
        this.baseSearch.sorter.order = order.slice(0, -3)
        this.GET_HISTORY(JSON.stringify(this.baseSearch))
      }
    },
    searchEvent () {
      this.baseSearch.search.value = this.value
      this.GET_HISTORY(JSON.stringify(this.baseSearch))
    }
  },
  computed: {
    ...mapGetters('role', [
      'history',
      'tabType'
    ])
  },
  mounted () {
    this.GET_HISTORY(JSON.stringify(this.baseSearch))
  }
}
</script>
<style>
.roleHistory .at-tabs--border-card>.at-tabs__content {
  padding: 0;
}
.roleHistory .at-tabs--border-card>.at-tabs__header {
  background: #fff;
}
.roleHistory .at-tabs__nav-scroll {
  background: #ecf0f5;
}
.at-tabs--border-card>.at-tabs__header .at-tabs__item{
  transition:none
}
</style>
<style scoped>
.roleHistory {
  background: #fff;
  color: #5c6781;
  padding-bottom: 20px;
}
.page {
  padding-top: 20px;
  text-align: center;
}
.role-table {
  margin: 20px;
  margin-bottom: 0px;
  border: 1px solid #eee;
}
.search {
  float: right;
}
.table-title {
  font-weight: bold;
  height: 50px;
  padding-left: 20px;
  line-height: 50px;
  font-size: 12px;
  border-bottom: 1px solid #eee;
}
.table-wrap {
  padding: 10px 20px 20px;
}
</style>


